package r21310.chap06.d1125;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Demo01Lambda {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        Collections.addAll(list,20,30,89,1,5,75,15,24,58);
        //Collections.sort(list ,( o1,  o2)->  o1-o2);------------简化
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });//----------------原来的版本
        System.out.println(list);
       // Collections.sort(list,(s1,s2)->s1-s2);



      /*  list.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });*/
        list.forEach( integer-> System.out.println(integer));
        final int[] sum={0};
        list.forEach(s->sum[0]+=s);
        System.out.println(sum[0]);



    }
}
